package com.daybook.service.impl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.daybook.mapper.OrderMapper;
import com.daybook.mapper.ShopCartMapper;
import com.daybook.pojo.Order;
import com.daybook.pojo.ShopCart;
import com.daybook.pojo.ShopCartAndBooks;
import com.daybook.service.ShopCartService;
@Service
public class ShopCartServiceImpl implements ShopCartService {
	@Autowired
	private ShopCartMapper shopCartMapper;

	//添加商品到购物车
	@Override
	public int addNewCart(ShopCart shopCart) {
		int res=-1;
		ShopCart oldCart=shopCartMapper.selectShopCartByBidAndUid(shopCart);
		Timestamp addtime=new Timestamp(System.currentTimeMillis());  
		shopCart.setStime(addtime);
		if(oldCart!=null){//购物车已存在
			shopCart.setSid(oldCart.getSid());
			res=shopCartMapper.updateNumCartById(shopCart);
		}else{//购物车不存在
			shopCart.setSnum(1);
			res=shopCartMapper.addNewCart(shopCart);
		}
		return res;
	}
	
	@Override
	public int updateCartById(ShopCart shopCart) {
		Timestamp addtime=new Timestamp(System.currentTimeMillis());  
		shopCart.setStime(addtime);
		return shopCartMapper.updateCartById(shopCart);
		
	}
	//删除单条购物车商品
	@Override
	public int deleteOneCartById(int sid) {
		
		return shopCartMapper.deleteOneCartById(sid);
	}
	//删除多条购物车商品
	@Override
	public int deleteCartByListId(Integer[] sidList) {
		// TODO Auto-generated method stub
		
		return shopCartMapper.deleteCartByListId(sidList);
	}
	//获得条购物车信息列表
	@Override
	public List<ShopCartAndBooks> getMyCartList(int uid) {
		return shopCartMapper.selectMyCartList(uid);
	}
	

}
